import { debounce } from "common/utils";
import BackTop from "components/content/backTop/BackTop";
import { BACKTOP_DISTANCE } from "common/const";

export const itemListenerMixin = {
  data() {
    return {
      itemImgListener: null,
    };
  },
  mounted() {
    let refreash = debounce(this.$refs.scroll.refresh, 200);

    this.itemImgListener = () => {
      refreash();
    };

    this.$bus.$on("itemImageLoad", this.itemImgListener);
  },
};

export const backTopMixin = {
  components: {
    BackTop,
  },
  data() {
    return {
      isShowBackTop: false,
    };
  },
  methods: {
    backClick() {
      // console.log("backTop点击");
      this.$refs.scroll.scroll.scrollTo(0, 0, 600);
    },
    listenShowBackTop(position) {
      this.isShowBackTop = -position.y > BACKTOP_DISTANCE;
    },
  },
};
